|
1
|
|
|
GLSR.pinned = function( options ) { |
|
|
|
|
|
|
2
|
|
|
this.options = x.extend( {}, this.defaults, options ); |
|
|
|
|
|
|
3
|
|
|
this.el = x( this.options.selector ); |
|
4
|
|
|
this.target = null; |
|
5
|
|
|
if( !this.el )return; |
|
|
|
|
|
|
6
|
|
|
this.init(); |
|
7
|
|
|
}; |
|
8
|
|
|
|
|
9
|
|
|
GLSR.pinned.prototype = { |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
defaults: { |
|
12
|
|
|
selector: '#pinned-status-select', |
|
13
|
|
|
}, |
|
14
|
|
|
|
|
15
|
|
|
/** @return void */ |
|
16
|
|
|
init: function() { |
|
17
|
|
|
x( 'a.cancel-pinned-status' ).on( 'click', this.onClickCancel.bind( this )); |
|
18
|
|
|
x( 'a.edit-pinned-status' ).on( 'click', this.onClickEdit.bind( this )); |
|
19
|
|
|
x( 'a.save-pinned-status' ).on( 'click', this.onClickSave.bind( this )); |
|
20
|
|
|
x( 'table td.sticky i' ).on( 'click', this.onClickToggle.bind( this )); |
|
21
|
|
|
}, |
|
22
|
|
|
|
|
23
|
|
|
/** @return void */ |
|
24
|
|
|
onClickCancel: function( ev ) { |
|
25
|
|
|
ev.preventDefault(); |
|
26
|
|
|
this.el.slideUp( 'fast' ).siblings( 'a.edit-pinned-status' ).show().focus(); |
|
27
|
|
|
this.el.find( 'select' ).val( x( '#hidden-pinned-status' ).val() === '0' ? 1 : 0 ); |
|
28
|
|
|
}, |
|
29
|
|
|
|
|
30
|
|
|
/** @return void */ |
|
31
|
|
|
onClickEdit: function( ev ) { |
|
32
|
|
|
ev.preventDefault(); |
|
33
|
|
|
if( !this.el.is( ':hidden' ))return; |
|
|
|
|
|
|
34
|
|
|
this.el.slideDown( 'fast', function() { |
|
35
|
|
|
this.el.find( 'select' ).focus(); |
|
36
|
|
|
}.bind( this )); |
|
37
|
|
|
x( this ).hide(); |
|
38
|
|
|
}, |
|
39
|
|
|
|
|
40
|
|
|
/** @return void */ |
|
41
|
|
|
onClickSave: function( ev ) { |
|
42
|
|
|
ev.preventDefault(); |
|
43
|
|
|
this.el.slideUp( 'fast' ).siblings( 'a.edit-pinned-status' ).show().focus(); |
|
44
|
|
|
this.target = ev.target; |
|
45
|
|
|
var request = { |
|
46
|
|
|
action: 'toggle-pinned', |
|
47
|
|
|
id: x( '#post_ID' ).val(), |
|
48
|
|
|
pinned: x( '#pinned-status' ).val(), |
|
49
|
|
|
}; |
|
50
|
|
|
this.request( request, this.save.bind( this )); |
|
51
|
|
|
}, |
|
52
|
|
|
|
|
53
|
|
|
/** @return void */ |
|
54
|
|
|
onClickToggle: function( ev ) { |
|
55
|
|
|
ev.preventDefault(); |
|
56
|
|
|
this.target = ev.target; |
|
57
|
|
|
var request = { |
|
58
|
|
|
action: 'toggle-pinned', |
|
59
|
|
|
id: ev.target.getAttribute( 'data-id' ), |
|
60
|
|
|
}; |
|
61
|
|
|
this.request( request, this.toggle.bind( this )); |
|
62
|
|
|
}, |
|
63
|
|
|
|
|
64
|
|
|
/** @return void */ |
|
65
|
|
|
request: function( request, callback ) { |
|
66
|
|
|
var data = { |
|
67
|
|
|
action: site_reviews.action, |
|
|
|
|
|
|
68
|
|
|
request: request, |
|
69
|
|
|
}; |
|
70
|
|
|
x.post( site_reviews.ajaxurl, data, callback.bind( this )); |
|
|
|
|
|
|
71
|
|
|
}, |
|
72
|
|
|
|
|
73
|
|
|
/** @return void */ |
|
74
|
|
|
save: function( response ) { |
|
75
|
|
|
x( '#pinned-status' ).val( !response.pinned|0 ); |
|
76
|
|
|
x( '#hidden-pinned-status' ).val( response.pinned|0 ); |
|
77
|
|
|
x( '#pinned-status-text' ).text( response.pinned ? this.target.data( 'yes' ) : this.target.data( 'no' )); |
|
78
|
|
|
// GLSR.insertNotices( response.notices ); |
|
79
|
|
|
}, |
|
80
|
|
|
|
|
81
|
|
|
/** @return void */ |
|
82
|
|
|
toggle: function( response ) { |
|
83
|
|
|
var action = response.pinned ? 'add' : 'remove'; |
|
84
|
|
|
this.target[action + 'Class']( 'pinned' ); |
|
85
|
|
|
}, |
|
86
|
|
|
}; |
|
87
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.